# -*- coding: utf-8 -*-
# @Time    : 2021/5/7 22:25
# @Author  : Zhangrenjie
# @Email   : zhangrenjie1998@163.com
# @File    : ATM.py
# @Software: PyCharm
class ATM():
    def __init__(self, name, money):
        self.name = name
        self.money = float(money)

    # 查看
    def check_money(self):
        print(f'余额为{self.money}')

    # 存钱
    def save_money(self, money):
        self.money += money

    # 取钱
    def get_money(self, money):
        if self.money < money:
            return False
        else:
            self.money -= money
            return True


class user():
    def __init__(self, username, userpasswd, money):
        self.username = username
        self.userpasswd = userpasswd
        self.money = float(money)

    # 登陆
    def login(self,username,userpasswd):
        if username == self.username and userpasswd == self.userpasswd:
            return True
        else:
            return False

    # 存钱
    def save_usermoney(self, money, ATMobj):
        ATMobj.money += money
        self.money += money

    # 查看
    def check_money(self):
        print(f'余额为{self.money}')

    # 取钱
    def get_usermoney(self, money, ATMobj):
        if self.money >= money and ATMobj.money >= money:
            self.money -= money
            ATMobj.money -= money
            return True
        else:
            return False




# 银行实例化
bank1 = ATM("SC",50000)
bank2 = ATM("SC",20000)
# 用户实例化
user1 = user('zzz', '123123', 1000)
user2 = user('zz', '123123', 3000)

choose = input(f'请问你要使用哪个ATM了\n1,bank1\n2,bank2')
if choose == '1':
    print(f"++++++++欢迎使用bank1——ATM++++++++\n1,管理员操作\n2，用户操作")
    bank = bank1
else:
    bank = bank2
    print(f"++++++++欢迎使用bank2——ATM++++++++\n1,管理员操作\n2，用户操作")
choose2 = input()
if choose2 == '2':
    # 管理员操作or用户操作
    i = 0
    while i < 3:
        i += 1
        username = input("请输入用户名：")
        userpasswd = input("请输入密码：")
        if user1.login(username, userpasswd):
            print("登陆成功")
            break
        else:
            if i < 3:
                print(f"用户名或密码错误！\t您还有{3 - i}次机会")
            else:
                print("您的账号输入密码错误过多，用户已冻结！")
                exit()

    # 登陆成功
    while True:
        print("1.取钱\n2.存钱\n3.查询\n4.退出")
        admin_input = input("请进行操作！")
        if admin_input == '1':
            money = float(input("请输入取出金额："))
            if user1.get_usermoney(money, bank):
                print("提取成功！")
            else:
                print("提取失败")
        elif admin_input == '2':
            money2 = float(input("请输入存放金额："))
            user1.save_usermoney(money2, bank)

        elif admin_input == '3':
            user1.check_money()
            bank.check_money()
        elif admin_input == "4":
            exit()
else:
    while True:
        print("1.取钱\n2.存钱\n3.查询\n4.退出")
        admin_input = input("请进行操作！")
        if admin_input == '1':
            money = float(input("请输入取出金额："))
            if bank.get_money(money):
                print("提取成功！")
            else:
                print("提取失败")
        elif admin_input == '2':
            money2 = float(input("请输入存放金额："))
            bank.save_money(money2)

        elif admin_input == '3':
            bank.check_money()
        elif admin_input == "4":
            exit()
